local time = 0
local blink = false

MgHUD_Ammo = 
{
    userData = {}
}
registerWidget("MgHUD_Ammo");

local function lowAmmo(weapon)
    return weapon.ammo <= weapon.lowAmmoWarning
end


function MgHUD_Ammo:draw()

    ------ Early out if HUD shouldn't be shown. ------
    if not shouldShowHUD() then return end
	if isRaceMode() then return end

    ------ INCR TIME ------
    time = time + deltaTime;

    ------ GET PLAYER ------
    local player = getPlayer();

    ------ OPTIONS ------
    local enableWeaponColors = false;

    ------ HELPERS ------
    local weaponIndexSelected = player.weaponIndexSelected;
    local weapon = player.weapons[weaponIndexSelected];
    local ammo = weapon.ammo;

    ------ COLORS ------
    local ammoColor

    if weapon.ammo == 0 then
        ammoColor = Color(128,128,128)
    elseif enableWeaponColors then
        ammoColor = weapon.color
    else
        ammoColor = Color(255,255,255)
    end

    ------ LOW AMMO BOX ------

    local boxLength = 110;
    if weapon.ammo > 9 then boxLength = boxLength + 80 end
    if weapon.ammo > 99 then boxLength = boxLength + 80 end

    if (weapon.ammo <= weapon.lowAmmoWarning) then
        local alpha = 160
        if time%0.4 > 0.2 then alpha = 60 end
        nvgBeginPath();
        nvgFillColor(Color(200,0,0,alpha));
        nvgRect(-15,-3,boxLength,108);
        nvgFill()
    end

    ------ TEXT FORMATTING -------
    nvgFontSize(130);
    nvgFontFace("CodeProLC");
    nvgTextAlign(NVG_ALIGN_LEFT, NVG_ALIGN_TOP);

    ------ DRAW TEXT ------
    nvgFillColor(Color(48,48,48))
    nvgText(4, 2, ammo);  -- drop shadow
    nvgFillColor(ammoColor)
    nvgText(0, 0, ammo);

--     nvgBeginPath();
--     nvgFillColor(Color(0,0,0,192));
--     nvgRect(85,5,10,95);
--     nvgFill();
    


end
